<%@page import="com.google.android.gcm.server.Result"%>
<%@page import="com.google.android.gcm.server.MulticastResult"%>
<%@page import="java.util.List"%>
<%@page import="com.google.android.gcm.server.Message"%>
<%@page import="com.google.android.gcm.server.Sender"%>
<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.ApiHandler.XmlData"%>
<%@page import="java.util.ArrayList"%>
<%
	DBHandler.getInstance().connect();

	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	String regId = web.getValue("regId");
	String msg = web.getValue("msg");
	
	Sender sender = new Sender("AIzaSyBfwDUfvGLZARl6E8nNSC2LVUWPM4Wnosg");

	Message message = new Message.Builder().addData("msg", msg).build();

	List<String> list = new ArrayList<String>();
	list.add(regId);

	MulticastResult multiResult = sender.send(message, list, 5);

	if (multiResult != null) {
		List<Result> resultList = multiResult.getResults();
		for (Result result : resultList) {
			System.out.println(result.getMessageId());
		}
	}
	
	DBHandler.getInstance().disconnect();
	
	ArrayList<XmlData> list2 = new ArrayList<XmlData>();
	web.result("SUCCESS", "푸쉬가 등록되었습니다.", list2);
%>